package com.lottery.ruok.lottrey.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lottery.ruok.lottrey.adapter.fragmentManager.ChargeFragmentManager;
import com.lottery.ruok.lottrey.fragment.ChargeItemsFragment;
import com.lottery.ruok.lottrey.retrofitModule.response.GetPayTypeResponse;

import java.util.ArrayList;
import java.util.List;

public class ChargeAdapter extends FragmentPagerAdapter {
    private List<GetPayTypeResponse> list;

    public ChargeAdapter(FragmentManager fm) {
        super(fm);
        this.list = new ArrayList<GetPayTypeResponse>();
    }

    public ChargeAdapter(FragmentManager fm, List<GetPayTypeResponse> list) {
        super(fm);
        this.list = list;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return list.get(position).getTitle();
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = ChargeFragmentManager.getFragment(position);
        if (fragment instanceof ChargeItemsFragment) {
            ChargeItemsFragment mFragment = (ChargeItemsFragment) fragment;
            mFragment.setData(list.get(position));
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    public void setList(List<GetPayTypeResponse> list) {
        this.list.clear();
        this.list.addAll(list);
        notifyDataSetChanged();
    }
}
